LC_EVENT_SNAP Home

LiteCAD generates LC_EVENT_SNAP event when a user moves a mouse inside of the graphics window. In the event procedure your application can analyse the current cursor position and correct it, to make an effect of sticking cursor to specific points when it goes nearby (like magnet).

The following properties are used for this event type:

Property Description
LC_PROP_EVENT_TYPE Value LC_EVENT_SNAP
LC_PROP_EVENT_WND Handle to a graphics window
LC_PROP_EVENT_DRW Handle to a drawing, viewed in the window
LC_PROP_EVENT_BLOCK Handle to active block (linked to the window)
LC_PROP_EVENT_FLOAT1
LC_PROP_EVENT_FLOAT2
X,Y cursor coordinates (drawing coordinate space)
LC_PROP_EVENT_FLOAT3 Snap distance
LC_PROP_EVENT_INT1
LC_PROP_EVENT_INT2
X, Y cursor coordinates (window coordinate space, pixels)
LC_PROP_EVENT_INT3 0 - the event have been generated on mouse movement.
1 - the event have been generated on mouse left button down

In order to notify LiteCAD that cursor must be snapped to specific point, within the event procedure call lcEventReturnCode function with non-zero parameter, and set properties LC_PROP_EVENT_FLOAT1 and LC_PROP_EVENT_FLOAT2 with coordinates X, Y of the specific point.

Code sample:
//-----------------------------------------------
void LcAppPaint::OnSnap (HANDLE hEvent)
{
  int i;
  CGePoint Pnt[6];
  HANDLE hLcWnd = lcPropGetHandle( hEvent, LC_PROP_EVENT_WND );
  double X = lcPropGetFloat( hEvent, LC_PROP_EVENT_FLOAT1 );
  double Y = lcPropGetFloat( hEvent, LC_PROP_EVENT_FLOAT2 );
  double Delta = lcPropGetFloat( hEvent, LC_PROP_EVENT_FLOAT3 );
  double Lef, Bot, Rig, Top;

  Pnt[0].Set(50,90);
  Pnt[1].Set(60,100);
  Pnt[2].Set(70,90);
  Pnt[3].Set(80,100);
  Pnt[4].Set(90,90);
  Pnt[5].Set(70,80);
  Lef = X - Delta;
  Bot = Y - Delta;
  Rig = X + Delta;
  Top = Y + Delta;
  for (i=0; i<6; i++){
    X = Pnt[i].x;
    Y = Pnt[i].y;
    if (Lef<X && X<Rig && Bot<Y && Y<Top){
      lcPropPutFloat( hEvent, LC_PROP_EVENT_FLOAT1, X );
      lcPropPutFloat( hEvent, LC_PROP_EVENT_FLOAT2, Y );
      lcEventReturnCode( 1 );
      return;
    }
  }
}